package pk1;
import java.io.IOException;
import shared.PMF;
import java.util.Date;
import shared.MyDateUtil;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.jdo.PersistenceManager;

public class InviteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String nextJSP = "MyInv.jsp";

	public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {

		request.setCharacterEncoding("BIG5");
		Date invite_date = MyDateUtil.getTodayDate();
		try {	
			invite_date = MyDateUtil.parse(request.getParameter("invite_date"));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			String inviterd_ID = request.getParameter("inviterd_ID");
			String inviter_ID = request.getParameter("inviter_ID");
			String invite_activity= request.getParameter("invite_activity");
			String inviterd_con=request.getParameter("inviterd_con");
			String inviter_con=request.getParameter("inviter_con");
			String invite_message = request.getParameter("invite_message");
			Invite inv = new Invite(inviterd_ID,inviter_ID,invite_activity,inviterd_con,inviter_con,invite_date,invite_message);
			pm.makePersistent(inv);
		} finally {
		    pm.close();
		}
		
		response.sendRedirect(nextJSP);
		
    }
	public void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws IOException, ServletException{
		doGet(request, response);
	}
	
	
	
}//AddProductServlet